<?php
/**
 * Description of ArrayValueValidator
 *
 * @author Samsung
 */
class ArrayValueValidator extends CValidator {
    
    public $min=1;
    public $allowEmpty=true;
    public $range=array();
    public $emptyMessage = '{attribute} cannot be blank.';
    public $minMessage = 'Please select at least {min} {attribute}.';
    public $rangeMessage = '{attribute} is not in range.';
    
    protected function validateAttribute($object, $attribute) {
        if($this->isEmpty($object->$attribute) && !$this->allowEmpty){
            $this->addError($object, $attribute, $this->emptyMessage);
        }elseif(count(array_filter($object->$attribute)) < $this->min){
            $this->addError($object, $attribute, $this->minMessage, array('{min}'=>$this->min));
        }elseif(array_intersect(array_filter($object->$attribute), $this->range) != array_filter($object->$attribute)){
            $this->addError($object, $attribute, $this->rangeMessage);
        }        
    }
}